package com.cictec.middleware.gps.engine.event.listener;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.cictec.middleware.gps.engine.TimeEventBus;
import com.cictec.middleware.gps.engine.event.BeforeAfterDistanceEvent;
import com.cictec.middleware.gps.engine.service.StationNumberService;
import com.google.common.eventbus.Subscribe;


/**
 * 设备上下线 事件处理监听【中间件外部事件】
 * @author Administrator
 *
 */
@Component
public class BeforeAfterDistanceEventListener {
	
	private static Logger logger = LoggerFactory.getLogger(BeforeAfterDistanceEventListener.class);
	
	@Autowired
	private TimeEventBus timeEventBus;

	@Autowired
	private StationNumberService stationNumberService;
	
	@PostConstruct
	public void init() {
		logger.debug("注册【BeforeAfterDistanceEventListener】前后车距事件到TimeEventBus， 触发事件：BeforeAfterDistanceEvent");
		timeEventBus.register(this);

	}
	
	/**
	 * 前后车距
	 * @param event
	 */
	@Subscribe
	public void onHandler(BeforeAfterDistanceEvent event){
		logger.debug(" 设备在线、离线状态 发生变化，更新数据库；重新发布车辆位置信息");
		
		stationNumberService.sendBeforeAfterStationNumber(event.getLineUuid(), event.getLineType(), event.getBusUuid());
	}
	

}
